package br.com.monise.view;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;

import br.com.monise.service.Geracao;

public class Simulacao extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	public static JTextArea txtConteudo;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		
		for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
				.getInstalledLookAndFeels()) {
			if ("Nimbus".equals(info.getName())) {
				try {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
				} catch (ClassNotFoundException ex) {
					Logger.getLogger(TelaInicial.class.getName()).log(
							Level.FINE, null, ex);
				} catch (InstantiationException ex) {
					Logger.getLogger(TelaInicial.class.getName()).log(
							Level.FINE, null, ex);
				} catch (IllegalAccessException ex) {
					Logger.getLogger(TelaInicial.class.getName()).log(
							Level.FINE, null, ex);
				} catch (UnsupportedLookAndFeelException ex) {
					Logger.getLogger(TelaInicial.class.getName()).log(
							Level.FINE, null, ex);
				}
				break;
			}
		}
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Simulacao frame = new Simulacao();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Simulacao() {
		setBackground(new Color(255, 255, 255));
		setTitle("Simula\u00E7\u00E3o Aprendiz Formal");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 526, 413);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.control);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JButton btnSimular = new JButton("Simular");
		btnSimular.setIcon(new ImageIcon(Simulacao.class.getResource("/imagens/start.png")));
		
		JButton btnParar = new JButton("Fechar");
		btnParar.setIcon(new ImageIcon(Simulacao.class.getResource("/imagens/Remove.png")));
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(148)
							.addComponent(btnSimular)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnParar)))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(13)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 299, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnSimular)
						.addComponent(btnParar)))
		);
		
		 txtConteudo = new JTextArea();
		scrollPane.setViewportView(txtConteudo);
		contentPane.setLayout(gl_contentPane);
		
		btnSimular.addActionListener(new GeraSimualcao());
		btnParar.addActionListener(new FechaSistema());
	}

	private class GeraSimualcao implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			Geracao geracao = new Geracao();
			try {
				geracao.iniciarSimulacao();				
			} catch (Exception e) {
				e.printStackTrace();
			}			
		}
	}
	
	private class FechaSistema implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			System.exit(0); 		
		}
	}
}
